﻿<?php
/*查询所有的学生表格*/
('Access-Control-Allow-Origin：*');
include("../config/mysql.php");
$searchName = $_REQUEST['searchName'];
$searchCardid = $_REQUEST['searchCardid'];
$searchSchool = $_REQUEST['searchSchool'];
$educationType = $_REQUEST['educationType'];
$searchTeacher = $_REQUEST['searchTeacher'];
$ispay = $_REQUEST['ispay'];
$isBao = $_REQUEST['isBao'];
$scale = $_REQUEST['scale'];
$userid = $_REQUEST['userid'];
$createtime = $_REQUEST['createtime'];
$province = $_REQUEST['province'];
$searchUnifiedExam = $_REQUEST['searchUnifiedExam'];
$searchPaper = $_REQUEST['searchPaper'];
$searchBaccalaureate = $_REQUEST['searchBaccalaureate'];
$signUpTime = $_REQUEST['signUpTime'];
$signUpYear = $_REQUEST['signUpYear'];
$veteran = $_REQUEST['veteran'];
$cengci = $_REQUEST['cengci'] == "0" ? "" : $_REQUEST['cengci'];
$limit = $_REQUEST['limit'];
$page = $_REQUEST['page'];
$company_id = $_REQUEST['company_id'];
$recycle_bin = $_REQUEST['recycle_bin'];

$sql = "SELECT s.Refund,s.isRefund,s.id,s.name,s.phone,s.cardid,s.cengci,ce.name AS cengci_name,s.mail,s.sosperson,s.sosphone,t.tname,s.school,s.major,s.money,s.ispay,s.creattime,s.educationType,e.name AS educationtype_name,s.remarks,s.isTi,s.oweafee,s.isBao,s.unifiedExam,s.paper,s.baccalaureate,s.chengben,s.signUpTime,s.signUpYear,s.downLoadPath,s.veteran,c.companyName FROM students s INNER JOIN teachers t ON s.tid = t.id INNER JOIN company c ON s.company_id = c.id INNER JOIN cengci ce ON s.cengci = ce.id INNER JOIN educationType e ON s.educationType = e.id WHERE s.name LIKE '%{$searchName}%' AND s.cardid LIKE '%{$searchCardid}%' AND s.isBao LIKE '%{$isBao}%' AND s.school LIKE '%{$searchSchool}%' AND t.tname LIKE '%{$searchTeacher}%' AND s.ispay LIKE '%{$ispay}%' AND s.creattime LIKE '%{$createtime}%' AND s.unifiedExam LIKE '%{$searchUnifiedExam}%' AND s.paper LIKE '%{$searchPaper}%' AND s.baccalaureate LIKE '%{$searchBaccalaureate}%' AND s.signUpTime LIKE '%{$signUpTime}%' AND s.signUpYear LIKE '%{$signUpYear}%' AND s.cengci LIKE '%{$cengci}%' AND s.veteran LIKE '%{$veteran}%' AND s.company_id = {$company_id} AND s.recycle_bin = {$recycle_bin}";

if ($province == "1") {
    $sql .= " AND LEFT(`cardid`,6) BETWEEN 230000 AND 239999";
} else if ($province == "2") {
    $sql .= " AND LEFT(`cardid`,6) NOT BETWEEN 230000 AND 239999";
}
// if ($scale == 1) {
// } else if ($scale == 2) {
// }
if ($scale == 3 || $scale == 4 || $scale == 5) {
    $sql .= " AND s.tid = '{$userid}'";
}
if ($educationType != 0) {
    $sql .= " AND s.educationType = {$educationType}";
}
// if ($userid != 3) {
//     $sql .= " AND s.company_id = {$company_id}";
// }
$Mysql = new Mysql();
$count = $Mysql->getResultNum($sql);
if ($count > 0) {
    $start = ($page - 1) * $limit;
    $sql .= ' order by s.id desc';
    $sql .= " limit {$start},{$limit}";
    /*查询表格参数一表明   参数二 查询语句*/
    $arr = $Mysql->LIKESelectLayui($sql);
}

/*返回出去*/
if (is_array($arr) == 1) {
    $res = [
        'code' => 0,
        'msg' => '查询成功',
        'count' => $count,
        'data' => $arr
    ];
} else {
    $res = [
        'msg' => '没有查到数据',
    ];
}
echo json_encode($res, JSON_UNESCAPED_UNICODE);
/*关闭连接*/
$Mysql->close();
